package com.fh.web.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fh.common.util.ConvertUtils;
import com.fh.common.web.impl.AbstractServiceImpl;
import com.fh.modules.ucas.entity.SysRolePermission;
import com.fh.web.mapper.SysRolePermissionMapper;
import com.fh.web.service.ISysRolePermissionService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Qiu, Junda
 * @date 2019年4月3日
 * @description 角色权限表 服务实现类
 */
@Service
public class SysRolePermissionServiceImpl extends AbstractServiceImpl<SysRolePermissionMapper, SysRolePermission> implements ISysRolePermissionService {

    @Override
    public void saveRolePermission(String roleId, String permissionIds) {
        LambdaQueryWrapper<SysRolePermission> query = new QueryWrapper<SysRolePermission>().lambda().eq(SysRolePermission::getRoleId, roleId);
        this.remove(query);
        List<SysRolePermission> list = new ArrayList<SysRolePermission>();
        String arr[] = permissionIds.split(",");
        for (String p : arr) {
            if (ConvertUtils.isNotEmpty(p)) {
                SysRolePermission rolepms = new SysRolePermission(roleId, p);
                list.add(rolepms);
            }
        }
        this.saveBatch(list);
    }

}
